package com.wodan.zhongjinjicang.common.orm.metadata;

import java.util.Map;

import com.wodan.zhongjinjicang.common.orm.annotation.Table;
import org.springframework.util.Assert;

import com.google.common.collect.Maps;


public class MetaDataFactory {
	private static final Map<Class<?>, TableMetaData> TABLE_METADATA_MAP = Maps.newHashMap();

	public static TableMetaData createTableMetaData(Class<?> clazz) {
		Assert.notNull(clazz);

		TableMetaData metaData = TABLE_METADATA_MAP.get(clazz);
		if (metaData == null) {
			metaData = new TableMetaData(clazz);
			TABLE_METADATA_MAP.put(clazz, metaData);
		}

		return metaData;
	}

	private static final Map<Class<?>, MapperInterfaceMetaData> MAPPER_INTERFACE_META_DATA_CACHE = Maps.newHashMap();

	public static MapperInterfaceMetaData createMapperInterfaceMetaData(Class<?> clazz) {
		Assert.notNull(clazz);

		MapperInterfaceMetaData metaData = MAPPER_INTERFACE_META_DATA_CACHE.get(clazz);
		if (metaData == null) {
			metaData = new MapperInterfaceMetaData(clazz);
			MAPPER_INTERFACE_META_DATA_CACHE.put(clazz, metaData);
		}

		return metaData;
	}

	public static boolean isOrmEntity(Class<? extends Object> clazz) {
		Assert.notNull(clazz);

		Table tableAnnotation = clazz.getAnnotation(Table.class);
		if (tableAnnotation == null) {
			return false;
		}

		return true;
	}
}
